const name = 'conpons-select'

let mixToggle = function (propName = '', defVal, onSet = (v, oldVal) => {} ) {
  let dataName = propName + 'State'
  let ret = {}
  ret.data = function () {
    return {
      [dataName]: defVal
    }
  }
  ret.methods = {
    ['is' + propName.alFirstUpperCase()](v) {
      return this[dataName] === v
    },
    ['set' + propName.alFirstUpperCase()](v) {
      let oldVal = this[dataName]
      this[dataName] = v
      if (onSet) {
        onSet.bind(this)(v, oldVal)
      }
    }
  }
  return ret
}

export let CouponsSelect = {
  name,
  template: '#' + name + '-tpl',
  mixins: [
    mixToggle('activetab', 1, function (v, oldVal) {
      this.fetchData()
    }),
    mixToggle('selectedItemIndex', 1, function (v, oldVal) {

    })
  ],
  data() {
    return {
      items: []
    }
  },
  computed: {
    itemState() {
      if (this.isActivetab(1)) {
        return 'default'
      }
      if (this.isActivetab(2)) {
        return 'blocked'
      }
      return ''
    }
  },
  methods: {
    fetchData() {
      Promise.resolve().then(() => {
        this.items = [{}, {}, {}]
      })
    }
  }
}
